package com.artPreter.controller.pc;

import com.artPreter.pojo.*;
import com.artPreter.service.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Controller
public class ContentArticleContorller {

    @Autowired
    private IArticleService articleService;
    @Autowired
    private IArtistService artistService;
    @Autowired
    private IArtworkService artWorkService;
    @Autowired
    private IDepartService departService;
    @Autowired
    private IArtTypeService artTypeService;
    @Autowired
    private IDepartContentSectionService departContentSectionService;
    @Autowired
    private ISystemConfigService systemConfigService;

    @RequestMapping("/index/article/content/{contentId}")
    public String indexArticleContent(@PathVariable("contentId") String contentId, Model model) {

        // 系统设置
        HashMap systemConfig = systemConfigService.getSystemConfig();
        model.addAttribute("systemConfig",systemConfig);

        // 头部菜单
        List<DepartContentSection> menuList = departContentSectionService.getMenuList();
        for (int i = 0; i < menuList.size(); i++) {
            if(menuList.get(i).getContentId().equals(contentId)){
                menuList.get(i).setIsActice(1);
            }
        }
        model.addAttribute("menus",menuList);


        Integer currentPage = 1;

        IPage<Article> articleIPage = articleService.getPageRelativeFull(currentPage,99,contentId);
        System.out.println(articleIPage.getRecords().size()+"-------------");
        model.addAttribute("articles",articleIPage.getRecords());
        return "pc/company/simple_article_list";
    }

    @RequestMapping("/index/article/list")
    public String indexArticle(Integer cid, Model model) {

        // 系统设置
        HashMap systemConfig = systemConfigService.getSystemConfig();
        model.addAttribute("systemConfig",systemConfig);
        String contentId = null;

        // 头部菜单
        List<DepartContentSection> menuList = departContentSectionService.getMenuList();
        for (int i = 0; i < menuList.size(); i++) {
            if(menuList.get(i).getId().equals(cid)){
                menuList.get(i).setIsActice(1);
                contentId = menuList.get(i).getContentId();
            }
        }
        model.addAttribute("menus",menuList);
        model.addAttribute("cid",cid);


        Integer currentPage = 1;
        System.out.println(contentId+"id");
        IPage<Article> articleIPage = articleService.getPageRelativeFull(currentPage,99,contentId);
        System.out.println(articleIPage.getRecords().size()+"-------------");
        model.addAttribute("articles",articleIPage.getRecords());
        if(contentId==null){
            return "redirect:/";
        }
        return "pc/index/article_list";
    }

    @RequestMapping("/index/page")
    public String indexPage(Integer cid, Model model) {

        // 系统设置
        HashMap systemConfig = systemConfigService.getSystemConfig();
        model.addAttribute("systemConfig",systemConfig);
        String contentId = null;
        String content = "";
        // 头部菜单
        List<DepartContentSection> menuList = departContentSectionService.getMenuList();
        for (int i = 0; i < menuList.size(); i++) {
            if(menuList.get(i).getId().equals(cid)){
                menuList.get(i).setIsActice(1);
                contentId = menuList.get(i).getContentId();
                content = menuList.get(i).getPageDetail();
                System.out.println(content);
            }
        }

        model.addAttribute("menus",menuList);
        model.addAttribute("cid",cid);




        model.addAttribute("pageDetail",content);
        if(contentId==null){
            return "redirect:/";
        }
        return "pc/company/simple_page";
    }
}
